from odoo import api, fields, models


class RpRelatedModel(models.Model):
    _name = 'rp.related.model'
    _description = '关联模型'
    _sql_constraints = [('related_fields_and_record_uniq', 'unique(field_name_id, field_record_id)', '关联模型必须唯一！')]

    field_name_id = fields.Many2one(string='模型', comodel_name='ir.model')
    field_record_id = fields.Integer(string='记录ID')

    def name_get(self):
        result_list = []
        for record in self:
            result_list.append((record.id, '%s-%s' % (record.field_name_id.name, record.field_record_id)))
        return result_list
